package com.jjyu.controller;

import com.jjyu.entity.Feedback;
import com.jjyu.entity.Result;
import com.jjyu.service.FeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户反馈控制器
 */
@RestController
@RequestMapping("/feedback")
public class FeedBackController {
    @Autowired
    private FeedBackService feedbackService;

    /**
     * 添加反馈
     */
    @PostMapping("/add")
    public Result addFeedBack(@RequestBody Feedback feedback) {
        feedbackService.save(feedback);
        return Result.success("反馈添加成功");
    }

    /**
     * 获取用户的所有反馈
     */
    @GetMapping("/user/{userId}")
    public Result<List<Feedback>> getFeedBackByUserId(@PathVariable("userId") Integer userId) {
        List<Feedback> feedbacks = feedbackService.getFeedBackByUserId(userId);
        return Result.success(feedbacks);
    }

    /**
     * 删除反馈
     */
    @DeleteMapping("/{feedbackId}")
    public Result deleteFeedBack(@PathVariable("feedbackId") Integer id) {
        feedbackService.removeById(id);
        return Result.success("反馈已删除");
    }
}
